﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Application.Admin.Push
{
    public class PushContentsService : IPushContentsService
    {
        Domain.Uow.IRepository<Domain.Entity.PushContents> contentsRepository;

        public PushContentsService(Domain.Uow.IRepository<Domain.Entity.PushContents> contents)
        {
            if (contents == null)
            {
                throw new ArgumentNullException("contentsRepository is null");
            }
            contentsRepository = contents;
        }

        public Domain.Entity.PushContents Add(Domain.Entity.PushContents add, Domain.Entity.User operUser)
        {
            if (add == null) return add;
            contentsRepository.Add(add);
            contentsRepository.Uow.Commit();
            return add;
        }

        public bool Delete(Domain.Entity.PushContents delete, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                delete.State = false;
                contentsRepository.Modify(delete);
                contentsRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool DeleteTrue(Domain.Entity.PushContents delete, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                contentsRepository.Delete(delete);
                contentsRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool Delete(IList<int> idList, Domain.Entity.User operUser)
        {
            var res = false;
            var delete = contentsRepository.GetList(e => idList.Contains(e.Id));
            foreach (var item in delete)
            {
                item.State = false;
                contentsRepository.Modify(item);
            }
            try
            {
                contentsRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool DeleteTrue(IList<int> idList, Domain.Entity.User operUser)
        {
            var res = false;
            var delete = contentsRepository.GetList(e => idList.Contains(e.Id));
            foreach (var item in delete)
            {
                contentsRepository.Delete(item);
            }
            try
            {
                contentsRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool Modify(Domain.Entity.PushContents modify, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                contentsRepository.Modify(modify);
                contentsRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public Domain.Entity.PushContents Get(int id)
        {
            var data = contentsRepository.Get(id);
            return data;
        }

        public IQueryable<Domain.Entity.PushContents> GetList()
        {
            var data = contentsRepository.GetList();
            return data;
        }

    }
}
